package timer

import (
	"encoding/json"
	"time"
)

type runtimeTimer struct {
	Key       string
	TimerType Type
	Delay     time.Duration
	Data      interface{}
}

func newTimer(key string, timerType Type, duration time.Duration, data interface{}) *runtimeTimer {
	return &runtimeTimer{
		Key:       key,
		TimerType: timerType,
		Delay:     duration,
		Data:      data,
	}
}

func (r *runtimeTimer) ToRecord() *recordTimer {
	bs, err := json.Marshal(r.Data)
	if err != nil {
		return nil
	}
	return &recordTimer{
		Key:       r.Key,
		TimerType: r.TimerType,
		Delay:     r.Delay,
		Data:      bs,
	}
}
